########################
## tool set
########################
CC = i586-elf-gcc
CCFLAGS = -ffreestanding -nostdlib -fno-builtin -fno-exceptions -c
CXXFLAGS = -nostdlib -fno-builtin -fno-rtti -fno-exceptions -c

AS = nasm
ASFLAGS = -f elf

LD = i586-elf-ld
LDFLAGS = -T link.ld

COPY = cp $@ ./disk/$@

DISK = mkisofs -R -b grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o ./OS.iso ./disk

########################
## outputs
########################
PROGS = OS.OS
OS_OBJS = 	source/kernel/build_number.o	\
			source/kernel/main.o			\
			source/kernel/entry.o			\
			source/kernel/textscreen.o		\
			source/kernel/stdio.o			\
			source/kernel/GDT.o				\
			source/kernel/GDTasm.o			\
			source/kernel/IDT.o				\
			source/kernel/IDTasm.o			\
			source/kernel/IRQasm.o			\
			source/kernel/IRQ.o				\
			source/kernel/memory.o			\
			source/kernel/PIT.o		

########################
## targets
########################
all: $(PROGS)
	@$(DISK)
	
OS.OS:
	@./build_number.sh
	@make $(OS_OBJS)
	@echo Linking
	@$(LD) $(LDFLAGS) -o $@ $(OS_OBJS)
	@$(COPY)

clean:
	-@rm $(OS_OBJS) $(PROGS)


########################
## source rules
########################
.cpp.o:	global.h
	@echo making $@
	@$(CC) $(CXXFLAGS) -o $@ $<

.c.o: global.h
	@echo making $@
	@$(CC) $(CCFLAGS) -o $@ $<
	
.s.o:
	@echo making $@
	@$(AS) $(ASFLAGS) -o $@ $<




